﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.Design;
using Terralever.Facebook.UI.FbmlControls;
using System.ComponentModel.Design;

namespace Terralever.Facebook.UI.Design.FbmlControls
{
    public class StatusMessageDesigner : FbmlControlDesigner
    {
        private const string DIV_STD_STYLE = "padding: 10px; display: block; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;";
        private const string DIV_NO_PAD_STYLE = "padding: 0; display: block; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;";
        private const string DIV_NO_BOT_STYLE = "padding: 10px; padding-bottom: 0px; display: block; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;";
        private const string H1_STYLE = "font-weight: bold; margin: 0; padding: 10px; font-size: 14px; display: block; ";
        private const string P_STYLE = "font-weight: normal; line-height: normal; margin: 4px 0 0; font-size: 11px; display: block;";

        private const string ERROR_COLORS = "background: #ffebe8 none repeat scroll 0 0; border: 1px solid #dd3c10; color: #333333;";
        private const string SUCCESS_COLORS = "background: #fff9d7 none repeat scroll 0 0; border: 1px solid #e2c822; color: #333333;";
        private const string EXPLANATION_COLORS = "background: #ffffff none repeat scroll 0 0; border: 1px solid #bdc7d8; color: #333333;";

        public override string GetDesignTimeHtml()
        {
            StatusMessageBase ctrl = Component as StatusMessageBase;
            StringBuilder sb = new StringBuilder();
            sb.Append("<div style=\"");
            if (ctrl.DecorationType == StatusMessageDecorationType.Standard)
            {
                sb.Append(DIV_STD_STYLE);
            }
            else if (ctrl.DecorationType == StatusMessageDecorationType.NoBottomPadding)
            {
                sb.Append(DIV_NO_BOT_STYLE);
            }
            else if (ctrl.DecorationType == StatusMessageDecorationType.NoTopPadding)
            {
                sb.Append(DIV_NO_PAD_STYLE);
            }
            sb.Append("\"><div style=\"");
            sb.Append(H1_STYLE);
            if (Component is Error)
            {
                sb.Append(ERROR_COLORS);
            }
            else if (Component is Success)
            {
                sb.Append(SUCCESS_COLORS);
            }
            else if (Component is Explanation)
            {
                sb.Append(EXPLANATION_COLORS);
            }
            sb.Append("\">");
            sb.Append(ctrl.Message);
            if (!string.IsNullOrEmpty(ctrl.Description))
            {
                sb.Append("<p style=\"");
                sb.Append(P_STYLE);
                sb.Append("\">");
                sb.Append(ctrl.Description);
                sb.Append("</p>");
            }
            sb.Append("</div></div>");
            return sb.ToString();
        }

        public override System.ComponentModel.Design.DesignerActionListCollection ActionLists
        {
            get
            {
                DesignerActionListCollection coll = new DesignerActionListCollection();
                coll.AddRange(base.ActionLists);
                return coll;
            }
        }
    }
}
